<template>
	<view class="salaryExamine">
		<view class="date-wrap">
			<view class="time">{{ nowTime }}</view>
			<view class="prograss" @click="checkPrograss">
				<!-- <view class="prograss-btn" @click="checkPrograss">审核进度</view> -->
				<view class="alluser-salary-detaile" @click="allUserSalary">查看详情</view>
			</view>
		</view>
		<view class="salary-details">
			<view class="real-salry">
				<view class="real-salry-title">实发合计:</view>
				<view>{{sumSalary.sf}}</view>
			</view>
			<view class="real-salry">
				<view class="real-salry-title">应发合计:</view>
				<view>{{sumSalary.yf}}</view>
			</view>
		</view>
		<view class="content">
			<view class="salary-card-sub" v-for="(item, index) in salaryData" :key="index">
				<salary-examine-card :salaryData="item"></salary-examine-card>
				<view class="btn" v-if="isExamine==0">
					<view @click="exit()" class="exit">工资表驳回</view>
					<view @click="adopt()" class="adopt">工资表通过</view>
				</view>
				
				<view class="btn" v-if="isExamine==1">
					<view @click="exitExamine()" class="exit">取消审批</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import apiData from '../../common/utils/apiData.js'
import service from '../../common/service/new_file.js'
export default {
	data() {
		return {
			nowTime: '2015-15',
			salaryData: [],
			title: 'Hello',
			allUserSalaryData:[],
			hvo:[],
			sumSalary:{},
			isExamine:'',
			pk:','
		};
	},
	methods: {
		checkPrograss(){
			// uni.navigateTo({
			// 	url:''
			// })
		},
		allUserSalary(){
			uni.navigateTo({
				url:'./slaryByGroupTable?item='+JSON.stringify(this.allUserSalaryData)
			})
		},
		exitExamine(){
			let _this = this
			let data = apiData.setExitExamineData(this.hvo.pk_payroll,'6302')//FN(billtype, isAdopt,pk)
			service.common(data, {
				success: function(res) {
						uni.showToast({
							icon:'none',
							title:'已取消审批,即将返回待办页'
						})
						setTimeout(()=>{
							uni.navigateTo({
								url:'./remineThing'
							})
						},1500)
					// _this.getLeaveList()
				},
				fail:function(err){
				},
				all:function(all){
				}
			})
		},
		adopt() {
			let _this = this
			let option = "审核通过"
			let data = apiData.setExamineData('6302',"Y",this.hvo.pk_payroll,option)
			service.common(data, {
				success: function(res) {
					uni.showToast({
						icon:'success',
						title:'已通过,即将返回待办页'
					})
					setTimeout(()=>{
						uni.navigateTo({
							url:'./remineThing'
						})
					},1500)
				},
				fail:function(err){
					console.log(err)
				},
				all:function(all){
					console.log(all)
				}
			})
		},
		exit() {
			let _this = this
			let option = "驳回此单据"
			let data = apiData.setExamineData('6302',"R",this.hvo.pk_payroll,option)
			service.common(data, {
				success: function(res) {
					uni.showToast({
						icon:'none',
						title:'已驳回,即将返回待办页'
					})
					setTimeout(()=>{
						uni.navigateTo({
							url:'./remineThing'
						})
					},1500)
				},
				fail:function(err){
					console.log(err)
				}
			})
		}
	},
	onReady() {
	},
	onLoad(option) {
		// this.pk = JSON.parse(option.item).hvo.pk_attendreport
		this.isExamine = option.isExamine
		this.nowTime = JSON.parse(option.item).hvo.cyear+'年'+JSON.parse(option.item).hvo.cperiod+'月'+JSON.parse(option.item).hvo.pk_wa_class.name
		this.allUserSalaryData=JSON.parse(option.item).psns
		this.sumSalary =  {
			sf:JSON.parse(option.item).hvo.sf,
			yf:JSON.parse(option.item).hvo.yf
		}
		this.hvo=JSON.parse(option.item).hvo
		this.salaryData =JSON.parse(option.item).depts
		let newMonthNum = parseInt(option.month) - 1;
		let month = new Date().setMonth(newMonthNum, 1);
		let timeCode = new Date(month);
		// this.nowTime = timeCode.getFullYear() + '年' + (timeCode.getMonth() + 1) + '月';
	}
};
</script>

<style scoped lang="scss">
	.salary-details{
		display: flex;
		flex-direction: column;
		color: #FFFFFF;
		padding: 0 36rpx;
		.real-salry{
			padding: 10rpx 20rpx;
			background: #007AFF;
			display: flex;
			align-items: center;
			font-size: 34rpx;
			border-radius: 10rpx;
			.real-salry-title{
				font-size: 28rpx;
				margin-right: 10rpx;
			}
		}
	}
.date-wrap {
	top: 88rpx;
	width: 100vw;
	display: flex;
	justify-content: space-between;
	align-items: center;
	.time {
		font-size: 28rpx;
		height: 100rpx;
		line-height: 100rpx;
		padding: 0 36rpx;
	}
	.prograss {
		display: flex;
		padding: 0 36rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #007aff;
		text-align: center;
		.prograss-btn{
			margin-right: 20rpx;
		}
	}
}
.btn {
	background: #faf9fa;
	align-items: center;
	width: 100vw;
	height: 100rpx;
	margin: 0 auto;
	display: flex;
	position: fixed;
	bottom: 0;
	.exit {
		color: #fe131a;
		height: 70%;
		display: flex;
		justify-content: center;
		align-items: center;
		flex: 1;
		text-align: center;
	}
	.adopt {
		display: flex;
		justify-content: center;
		align-items: center;
		flex: 1;
		text-align: center;
		height: 70%;
		border-left: 2rpx solid #e3e3e3;
		color: #36aa6a;
	}
}
.salary-card-sub {
	margin: 30rpx 0;
}
</style>
